<template>
  <div class="container">
    <el-button
      v-for="item in tileset3Ddata"
      :key="item.id"
      @click="flyIn3DTileset(item.id)"
      type="primary"
      >{{ item.name }}</el-button
    >
    <el-button type="primary" @click="flyIn3DTileset('title4')">BIM建模</el-button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ES3DTileset } from 'earthsdk3'
const props = defineProps({
  objm: {
    type: Object,
    required: true,
  },
})

const tileset3Ddata = ref([
  {
    id: 'title1',
    name: '倾斜摄影',
    url: 'https://www.pipeser.com/cesiumlab/G7qC5vBk/tileset.json',
  },
  {
    id: 'title2',
    name: '白模数据',
    url: 'https://www.pipeser.com/cesiumlab/7hfKb4S4/tileset.json',
    materialMode: 'technology',
  },
  {
    id: 'title3',
    name: '点云数据',
    url: 'https://www.pipeser.com/cesiumlab/KJSkNM0X/tileset.json',
    style: true,
  },
  // {
  //   id: 'title4',
  //   name: 'BIM建模',
  //   url: 'https://www.pipeser.com/cesiumlab/jgYgbe3y/tileset.json',
  //   bimStyle: true,
  // },
  {
    id: 'title5',
    name: '人工建模',
    url: 'https://www.pipeser.com/cesiumlab/L3NoFf4V/tileset.json',
  },
  {
    id: 'title6',
    name: '地下管线',
    url: 'https://www.pipeser.com/3dtiles/phipxrow1/tileset.json',
    style: true,
  },
])

//初始化3D Tileset 数据组
tileset3Ddata.value.forEach((item) => {
  const tileset = props.objm.createSceneObject(ES3DTileset, item.id)
  if (tileset) {
    tileset.url = item.url
    if (item.materialMode) {
      tileset.materialMode = item.materialMode //科技感
    }
    if (item.style) {
      tileset.czmStyleJson = { color: 'vec4(1,0,0,1)' } //设置样式
    }
  }
})

const BIMtileset = props.objm.createSceneObject(ES3DTileset, 'title4')
// 定义 emit
const emit = defineEmits(['bim-tileset-ready'])
BIMtileset.url = 'https://www.pipeser.com/cesiumlab/jgYgbe3y/tileset.json'
if (BIMtileset) {
  //// 屋顶着色
  BIMtileset.setFeatureColor('id', [
    {
      value: '6949fe393e9a4d4db7fe71339c61513800022318',
      rgba: [1, 0, 0, 1],
    },
  ])
  // 提供给其他组件使用
  //屋顶隐藏
  // tileset.setFeatureVisable('id', [
  //   {
  //     value: '6949fe393e9a4d4db7fe71339c61513800022318',
  //     visable: false,
  //   },
  // ])
}
if (BIMtileset) {
  // ... 设置属性
  emit('bim-tileset-ready', BIMtileset)
}

//根据3DTileset  id 飞行定位
const flyIn3DTileset = (id) => {
  const tileset = props.objm.getSceneObjectById(id)
  if (tileset) {
    tileset.flyTo()
  }
}
</script>

<style lang="scss" scoped>
.container {
  position: absolute;
  top: 80px;
  right: 10px;
  width: 600px;
  padding: 10px;
  border-radius: 5px;
  background-color: rgba(29, 37, 45, 0.8);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  button {
    height: 40px;
    margin: 0;
  }
}
</style>
